package com.nyist.pojo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @description 返回前端的数据包装
 * @author krzhou
 * @date 2017年5月9日
 *
 */
@SuppressWarnings("rawtypes")
public class ResultData {


	protected Logger logger = LoggerFactory.getLogger(getClass());
	/*
	 * 调用结果
	 */
	private boolean success;
	
	/*
	 * 错误或成功代码
	 */
	private int code;
	
	/*
	 * 服务器端返回消息
	 */
	private String msg;
	
	private String language;
	
	/*
	 * 数据对象
	 */
	private Object obj;
	
	private Map<String,Object> map;
	
	/*
	 * 集合数据对象
	 */
	private List list;

	public ResultData(){}
	
	public boolean success() {
		return success;
	}

	public int getCode() {
		return code;
	}

	public ResultData setCode(int code) {
		this.code = code;
		return this;
	}
	
	public boolean isSuccess() {
		return success;
	}
	public ResultData setSuccess(boolean success) {
		this.success = success;
		return this;
	}


	public ResultData setMsg(String msg) {
		this.msg = msg;
		return this;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public Object getObj() {
		return obj;
	}

	public ResultData setObj(Object data) {
		this.obj = data;
		return this;
	}

	public List getList() {
		return list;
	}

	public ResultData setList(List list) {
		this.list = list;
		return this;
	}

	public Map getMap() {
		return map;
	}

	public ResultData setMap(Map<String,Object> map) {
		this.map = map;
		return this;
	}
	
	public ResultData addAttribute(String key,Object value){
		if(this.map != null){
			this.map.put(key, value);
		}else{
			this.map = new HashMap<String,Object>();
			this.map.put(key,value);
		}
		return this;
	}
	
	
	public static ResultData result(boolean result){
		return new ResultData().setSuccess(result).setCode(result?200:500);
	}

	public String getMsg() {
		return msg;
	}
	
	
	
}
